﻿using System.Text;

namespace EkStudio.com.bean.xml.Unit
{
    public class WflowUtility
    {
        //****节点类型***************************************************

        ///<summary>开始节点</summary>
        public const string NODE_TYPE_START_UP_FLOW = "startUpFlow";
        ///<summary>审批节点</summary>
        public const string NODE_TYPE_COMMENT 	   = "commentFlow";
        ///<summary>判定节点</summary>
        public const string NODE_TYPE_CONDITION     = "conditionFlow";
        ///<summary>结束节点</summary>
        public const string NODE_TYPE_FINISH_FLOW   = "finishFlow";
        ///<summary>调用子审批流</summary>
        public const string NODE_TYPE_CHILDREN_FLOW = "childrenFlow";

        ///<summary>应用节点为审批节点</summary>
        public const string NODE_COMMENT_APPROVE_TYPE    = "StApprove";
        ///<summary>应用节点为流向节点</summary>
        public const string NODE_COMMENT_TRANSITION_TYPE = "StTransition";

        ///<summary>应用节点审批模式为并列关系</summary>
        public const string NODE_COMMENT_MODEL_AND = "StAndType";
        ///<summary>应用节点审批模式为或关系</summary>
        public const string NODE_COMMENT_MODEL_OR  = "StOrType";
	
	    public static object[] NODE_COMMENT_MODEL_TYPE = new object[]{NODE_COMMENT_MODEL_AND,NODE_COMMENT_MODEL_OR};



        ///<summary>超时节点默认无处理</summary>
        public const string NODE_TIMEOUT_OPERATION_STNONE = "StNone" ;

        ///<summary>超时节点以通过方式流转</summary>
        public const string NODE_TIMEOUT_OPERATION_STFLOW_AS_TRUE  = "StflowAsTrue";

        ///<summary>超时节点以否决方式流转</summary>
        public const string NODE_TIMEOUT_OPERATION_STFLOW_AS_FALSE = "StflowAsFalse";


        ///<summary>超时处理选项</summary>
        public static object[] NODE_TIMEOUT_OPERATION_TYPE = new object[]{NODE_TIMEOUT_OPERATION_STNONE,NODE_TIMEOUT_OPERATION_STFLOW_AS_TRUE,NODE_TIMEOUT_OPERATION_STFLOW_AS_FALSE};

        ///<summary>审批节点类型选项</summary>
        public static object[] NODE_COMMENT_TYPE_LIST = new object[]{NODE_COMMENT_APPROVE_TYPE,NODE_COMMENT_TRANSITION_TYPE};

        ///<summary>线落点位置上</summary>
        public const int POSTION_NODE_TOP    = 1;//上
        ///<summary>线落点位置左</summary>
        public const int POSTION_NODE_LEFT   = 2;//左
        ///<summary>线落点位置下</summary>
        public const int POSTION_NODE_BOTTOM = 3; //bottom
        ///<summary>线落点位置右</summary>
        public const int POSTION_NODE_RIGHT  = 4;//右
       





        ///<summary>工作流节点的扩展代码</summary>
        public static string getJavaCodeNode(string javaName, string packName)
        {
            StringBuilder javaCode = new StringBuilder();
            javaCode.Append("package ").Append(packName).Append(";\n");
            javaCode.Append("import org.apache.log4j.Logger;\n");
            javaCode.Append("import com.kootop.workflow.extend.Wf_BillNodeEventAbstract;\n");
            javaCode.Append("public class ").Append(javaName).Append(" extends Wf_BillNodeEventAbstract{\n");
            javaCode.Append("	private static Logger logger = Logger.getLogger(").Append(javaName).Append(".class);\n");
            javaCode.Append("	public ").Append(javaName).Append("(){\n\n\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void nodeFlowInEvent() throws Exception{\n");
            javaCode.Append("		 \n");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"执行节点的流入事件\");\n");
            javaCode.Append("		throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void nodeFlowOutEvent() throws Exception{\n");
            javaCode.Append("		 \n");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"执行节点的流出事件\");\n");
            javaCode.Append("		throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void nodeTimeOutEvent() throws Exception{\n");
            javaCode.Append("		 \n");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"执行节点的超时事件\");\n");
            javaCode.Append("		throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("}\n");

            return javaCode.ToString();
        }
        ///<summary>工作流模块全局扩展代码</summary>
        public static string getJavaCodeModule(string javaName, string packName)
        {
            StringBuilder javaCode = new StringBuilder();
            javaCode.Append("package ").Append(packName).Append(";\n\n");
            javaCode.Append("import com.kootop.common.user.User;\n");
            javaCode.Append("import org.apache.log4j.Logger;\n");
            javaCode.Append("import com.kootop.workflow.extend.Wf_BillModuleEventAbstract;\n\n");
            javaCode.Append("public class ").Append(javaName).Append(" extends Wf_BillModuleEventAbstract{\n\n");
            javaCode.Append("	private static Logger logger = Logger.getLogger(").Append(javaName).Append(".class);\n\n");
            javaCode.Append("	public ").Append(javaName).Append("(){\n\n\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void startUpEvent(User user) throws Exception{\n");
            javaCode.Append("		 ");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"执行启动扩展代码方法\");\n");
            javaCode.Append("		//throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void stopOffEvent(User user) throws Exception{\n");
            javaCode.Append("		 ");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"暂停工作流执行扩展代码方法\");\n");
            javaCode.Append("		//throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void rebootEvent(User user) throws Exception{\n");
            javaCode.Append("		 ");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"重启工作流执行扩展代码方法\");\n");
            javaCode.Append("		//throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void shutdownEvent(User user) throws Exception{\n");
            javaCode.Append("		 ");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"结束工作流启动扩展代码方法\");\n");
            javaCode.Append("		//throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");
            javaCode.Append("	@Override\n");
            javaCode.Append("	public void finishEvent() throws Exception{\n");
            javaCode.Append("		 ");
            javaCode.Append("		// 此处添加您的代码,请不要修改类默认结构\n");
            javaCode.Append("		logger.info(\"审批完成启动扩展代码方法\");\n");
            javaCode.Append("		//throw new UnsupportedOperationException(\"此方法未被重写,要求继承类必须重写此方法\");\n");
            javaCode.Append("	}\n");


            javaCode.Append("}\n");


            return javaCode.ToString();
        }
    }
}
